<HTML><HEAD><TITLE>is_list(?Term)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Type Testing</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>is_list(?Term)</H1>
Succeeds if Term is a proper list.
<DL>
<DT><EM>Term</EM></DT>
<DD>Prolog term.
</DD>
</DL>
<H2>Description</H2>
   Used to test whether Term is a proper list, i.e. either the empty list,
   of a list element whose tail is itself a proper list.  The predicate
   could be recursively defined as:
<PRE>
	is_list(X) :- var(X), !, fail.
	is_list([_|Xs]) :- is_list(Xs).
	is_list([]).
</PRE>
   The complexity of this operation is linear in the length of the list.

<H3>Modes and Determinism</H3><UL>
<LI>is_list(?) is semidet
</UL>
<H3>Fail Conditions</H3>
Fails if Term is not a proper list
<H2>Examples</H2>
<PRE>
    ?- is_list([]).
    Yes (0.00s cpu)

    ?- is_list([1,2,3]).
    Yes (0.00s cpu)

    ?- is_list([1,2|3]).   % illegal tail
    No (0.00s cpu)

    ?- is_list([1,2|_]).   % open-ended list
    No (0.00s cpu)

    ?- is_list(list).
    No (0.00s cpu)

    ?- is_list(42).
    No (0.00s cpu)

    ?- is_list(X).
    No (0.00s cpu)
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/typetest/atom-1.html">atom / 1</A>, <A HREF="../../kernel/typetest/callable-1.html">callable / 1</A>, <A HREF="../../kernel/typetest/compound-1.html">compound / 1</A>, <A HREF="../../kernel/typetest/ground-1.html">ground / 1</A>
</BODY></HTML>
